package com.leet.code.lcof;

import com.algorithm.model.ListNode;

public class Code24 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode head2 = new ListNode(2);
        ListNode head3 = new ListNode(3);
        head.next = head2;
        head2.next = head3;

        ListNode listNode = new Code24().reverseList(head);

        while (listNode != null) {
            System.out.println(listNode.val);
            listNode = listNode.next;
        }
    }


    public ListNode reverseList(ListNode head) {
        ListNode tmp, last = null;
        while (head != null) {
            tmp = head.next;
            head.next = last;
            last = head;
            head = tmp;
        }
        return last;
    }

}
